package com.mhf.controller;

import com.mhf.domain.JSONResult;
import com.mhf.domain.Movie;
import com.mhf.domain.MovieUser;
import com.mhf.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/movie")
public class MovieController {
    @Autowired
    private MovieService movieService;
    @GetMapping("/getById/{id}")
    public Movie getById(@PathVariable("id")Long id){

        return movieService.getById(id);
    }

    @PostMapping("/buyMovie")
    public JSONResult buyMovie(@RequestBody MovieUser movieUser){
        try {
            movieService.buyMovie(movieUser);

            return new JSONResult(true,"购买成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"失败");
        }
    }
    @GetMapping("/getByUserMovie/{userId}")
    public JSONResult getByUserMovie(@PathVariable("userId")Long userId){
        try {
            MovieUser byUserMovie = movieService.getByUserMovie(userId);
            JSONResult jsonResult = new JSONResult();
            jsonResult.setResultObj(byUserMovie);
            return jsonResult;
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"操作失败");
        }

    }
}
